# coding: utf-8

{{>partial_header}}

import warnings
from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt
from typing import Any, Dict, List, Optional, Tuple, Union
from typing_extensions import Annotated

{{#imports}}
{{import}}
{{/imports}}

from {{packageName}}.api_client import ApiClient, RequestSerialized
from {{packageName}}.api_response import ApiResponse
from {{packageName}}.rest import RESTResponseType


{{#operations}}
class {{classname}}:
    """NOTE: This class is auto generated by OpenAPI Generator
    Ref: https://openapi-generator.tech

    Do not edit the class manually.
    """

    def __init__(self, api_client=None) -> None:
        if api_client is None:
            api_client = ApiClient.get_default()
        self.api_client = api_client
{{#operation}}


    @validate_call
    {{#async}}async {{/async}}def {{operationId}}{{>partial_api_args}} -> {{{returnType}}}{{^returnType}}None{{/returnType}}:
{{>partial_api}}

        response_data = {{#async}}await {{/async}}self.api_client.call_api(
            *_param,
            _request_timeout=_request_timeout
        )
        {{#async}}await {{/async}}response_data.read()
        return self.api_client.response_deserialize(
            response_data=response_data,
            response_types_map=_response_types_map,
        ).data


    @validate_call
    {{#async}}async {{/async}}def {{operationId}}_with_http_info{{>partial_api_args}} -> ApiResponse[{{{returnType}}}{{^returnType}}None{{/returnType}}]:
{{>partial_api}}

        response_data = {{#async}}await {{/async}}self.api_client.call_api(
            *_param,
            _request_timeout=_request_timeout
        )
        {{#async}}await {{/async}}response_data.read()
        return self.api_client.response_deserialize(
            response_data=response_data,
            response_types_map=_response_types_map,
        )


    @validate_call
    {{#async}}async {{/async}}def {{operationId}}_without_preload_content{{>partial_api_args}} -> RESTResponseType:
{{>partial_api}}

        response_data = {{#async}}await {{/async}}self.api_client.call_api(
            *_param,
            _request_timeout=_request_timeout
        )
        return response_data.response


    def _{{operationId}}_serialize(
        self,
        {{#allParams}}
        {{paramName}},
        {{/allParams}}
        _request_auth,
        _content_type,
        _headers,
        _host_index,
    ) -> RequestSerialized:

        {{#servers.0}}
        _hosts = [{{#servers}}
            '{{{url}}}'{{^-last}},{{/-last}}{{/servers}}
        ]
        _host = _hosts[_host_index]
        {{/servers.0}}
        {{^servers.0}}
        _host = None
        {{/servers.0}}

        _collection_formats: Dict[str, str] = {
            {{#allParams}}
            {{#isArray}}
            '{{baseName}}': '{{collectionFormat}}',
            {{/isArray}}
            {{/allParams}}
        }

        _path_params: Dict[str, str] = {}
        _query_params: List[Tuple[str, str]] = []
        _header_params: Dict[str, Optional[str]] = _headers or {}
        _form_params: List[Tuple[str, str]] = []
        _files: Dict[
            str, Union[str, bytes, List[str], List[bytes], List[Tuple[str, bytes]]]
        ] = {}
        _body_params: Optional[bytes] = None

        # process the path parameters
{{#pathParams}}
        if {{paramName}} is not None:
            _path_params['{{baseName}}'] = {{paramName}}{{#isEnumRef}}.value{{/isEnumRef}}
{{/pathParams}}
        # process the query parameters
{{#queryParams}}
        if {{paramName}} is not None:
            {{#isDateTime}}
            if isinstance({{paramName}}, datetime):
                _query_params.append(
                    (
                        '{{baseName}}',
                        {{paramName}}.strftime(
                            self.api_client.configuration.datetime_format
                        )
                    )
                )
            else:
                _query_params.append(('{{baseName}}', {{paramName}}))
            {{/isDateTime}}
            {{#isDate}}
            if isinstance({{paramName}}, date):
                _query_params.append(
                    (
                        '{{baseName}}',
                        {{paramName}}.strftime(
                            self.api_client.configuration.date_format
                        )
                    )
                )
            else:
                _query_params.append(('{{baseName}}', {{paramName}}))
            {{/isDate}}
            {{^isDateTime}}{{^isDate}}
            _query_params.append(('{{baseName}}', {{paramName}}{{#isEnumRef}}.value{{/isEnumRef}}))
            {{/isDate}}{{/isDateTime}}
{{/queryParams}}
        # process the header parameters
{{#headerParams}}
        if {{paramName}} is not None:
            _header_params['{{baseName}}'] = {{paramName}}
{{/headerParams}}
        # process the form parameters
{{#formParams}}
        if {{paramName}} is not None:
            {{#isFile}}
            _files['{{{baseName}}}'] = {{paramName}}
            {{/isFile}}
            {{^isFile}}
            _form_params.append(('{{{baseName}}}', {{paramName}}))
            {{/isFile}}
{{/formParams}}
        # process the body parameter
{{#bodyParam}}
        if {{paramName}} is not None:
            {{#isBinary}}
            # convert to byte array if the input is a file name (str)
            if isinstance({{paramName}}, str):
                with open({{paramName}}, "rb") as _fp:
                    _body_params = _fp.read()
            elif isinstance({{paramName}}, tuple):
                # drop the filename from the tuple
                _body_params = {{paramName}}[1]
            else:
                _body_params = {{paramName}}
            {{/isBinary}}
            {{^isBinary}}
            _body_params = {{paramName}}
            {{/isBinary}}
{{/bodyParam}}

        {{#constantParams}}
        {{#isQueryParam}}
        # Set client side default value of Query Param "{{baseName}}".
        _query_params.append(('{{baseName}}', {{#_enum}}'{{{.}}}'{{/_enum}}))
        {{/isQueryParam}}
        {{#isHeaderParam}}
        # Set client side default value of Header Param "{{baseName}}".
        _header_params['{{baseName}}'] = {{#_enum}}'{{{.}}}'{{/_enum}}
        {{/isHeaderParam}}
        {{/constantParams}}

        {{#hasProduces}}
        # set the HTTP header `Accept`
        if 'Accept' not in _header_params:
            _header_params['Accept'] = self.api_client.select_header_accept(
                [{{#produces}}
                    '{{{mediaType}}}'{{^-last}}, {{/-last}}{{/produces}}
                ]
            )
        {{/hasProduces}}

        {{#hasConsumes}}
        # set the HTTP header `Content-Type`
        if _content_type:
            _header_params['Content-Type'] = _content_type
        else:
            _default_content_type = (
                self.api_client.select_header_content_type(
                    [{{#consumes}}
                        '{{{mediaType}}}'{{^-last}}, {{/-last}}{{/consumes}}
                    ]
                )
            )
            if _default_content_type is not None:
                _header_params['Content-Type'] = _default_content_type
        {{/hasConsumes}}

        # authentication setting
        _auth_settings: List[str] = [{{#authMethods}}
            '{{name}}'{{^-last}}, {{/-last}}{{/authMethods}}
        ]

        return self.api_client.param_serialize(
            method='{{httpMethod}}',
            resource_path='{{{path}}}',
            path_params=_path_params,
            query_params=_query_params,
            header_params=_header_params,
            body=_body_params,
            post_params=_form_params,
            files=_files,
            auth_settings=_auth_settings,
            collection_formats=_collection_formats,
            _host=_host,
            _request_auth=_request_auth
        )


{{/operation}}
{{/operations}}
